package com.lb.jwitter.action;


import java.util.ArrayList; 
import java.util.List; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import java.util.Map; 
 import com.opensymphony.xwork2.ActionContext; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyenService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHoSoXetTuyenSearchAction{
    private int pageSize; 
    public void setPageSize(int pageSize) {
       this.pageSize = pageSize;
     }

    public int getPageSize() {
       return pageSize;
 }

    private int page; 
    public void setPage(int page) { this.page = page;   }

    public int getPage() {
       return page;
   }

    private int pages; 
    public void setPages(int pages) { this.pages = pages;   }

    public int getPages() {
       return pages;
     }

    private String dataString; 
    public void setDataString(String dataString) { this.dataString = dataString;    }

    public String getDataString() {
       return dataString;
    }

    private Message msg; 
    public Message getMsg() { return msg; }

    /*private String diaChi; 
    public void setDiaChi(String diaChi) {
       this.diaChi = diaChi;
   }

    public String getDiaChi() {
       return diaChi;
   }

    private String dienThoai; 
    public void setDienThoai(String dienThoai) {
       this.dienThoai = dienThoai;
   }

    public String getDienThoai() {
       return dienThoai;
   }*/

    private String hoTen; 
    public void setHoTen(String hoTen) {
       this.hoTen = hoTen;
   }

    public String getHoTen() {
       return hoTen;
   }
    
    private String ten; 
    public void setTen(String ten) {
       this.ten = ten;
   }

    public String getTen() {
       return ten;
   }

    /*private String tungaySinh; 
    private String denngaySinh;*/
    
    private String noiSinh; 
    public void setNoiSinh(String noiSinh) {
       this.noiSinh = noiSinh;
   }

    public String getNoiSinh() {
       return noiSinh;
   }
    private String maHoSo;
    public void setMaHoSo(String maHoSo){
        this.maHoSo = maHoSo;
    }
    
    public String getMaHoSo(){
        return maHoSo;
    }
    private int ThongBaoId;
    public void setThongBaoId(int ThongBaoId){
        this.ThongBaoId = ThongBaoId;
    }
    
    public int getThongBaoId(){
        return ThongBaoId;
    }
    private int ChiNhanhId;
    public void setChiNhanhId(int ChiNhanhId){
        this.ChiNhanhId = ChiNhanhId;
    }
    
    public int getChiNhanhId(){
        return ChiNhanhId;
    }
    private int khoaId;
    public void setKhoaId(int khoaId){
        this.khoaId = khoaId;
    }
    
    public int getKhoaId(){
        return khoaId;
    }
    private int nganhId;
    public void setNganhId(int nganhId){
        this.nganhId = nganhId;
    }
    
    public int getNganhId(){
        return nganhId;
    }

    private List<TblQLDTTXAHoSoXetTuyen> tblQLDTTXAHoSoXetTuyens; 
    public List<TblQLDTTXAHoSoXetTuyen>  getTblQLDTTXAHoSoXetTuyens() {
        return tblQLDTTXAHoSoXetTuyens; 
      } 

    private TblQLDTTXAHoSoXetTuyenService tblQLDTTXAHoSoXetTuyenService; 

	private int preSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postSearch(Message msg, List<ConditionReport> cons ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSoXetTuyen", "xem")){ 
        return "noprivilege"; 
    } 
        tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient"); 
        msg = new Message(); 
        List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
    /*if(diaChi != null && !diaChi.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("diaChi");
        con.setValue1("%" + diaChi + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(dienThoai != null && !dienThoai.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("dienThoai");
        con.setValue1("%" + dienThoai + "%");
        con.setOperator("like");
        cons.add(con);	
    } */
    if(hoTen != null && !hoTen.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("hoTen");
        con.setValue1("%" + hoTen + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(ten != null && !ten.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("ten");
        con.setValue1("%" + ten + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    /*if( tungaySinh != null && !tungaySinh.equalsIgnoreCase("") ){ 
        ConditionReport con = new ConditionReport(); 
        con.setType("date"); 
         con.setCol("ngaySinh");
        con.setValue1(tungaySinh);
        if (denngaySinh != null && !denngaySinh.equalsIgnoreCase("") ){ 
            con.setValue2(denngaySinh); 
            con.setOperator("between"); 
        } 
        else{ 
            con.setOperator("ge"); 
        } 
        cons.add(con);	
    } 
        else if (denngaySinh != null && !denngaySinh.equalsIgnoreCase("") ){ 
        ConditionReport con = new ConditionReport(); 
        con.setType("date"); 
         con.setCol("ngaySinh");
        con.setValue1(denngaySinh);
        con.setOperator("le");
        cons.add(con);	
    } */
    if(noiSinh != null && !noiSinh.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("noiSinh");
        con.setValue1("%" + noiSinh + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(maHoSo != null && !maHoSo.equalsIgnoreCase("")){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("maHoSo");
        con.setValue1("%" + maHoSo + "%");
        con.setOperator("like");
        cons.add(con);	
    } 
    if(ThongBaoId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("thongBaoId.id");
        con.setValue1(new Long(ThongBaoId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(ChiNhanhId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("chiNhanhId.id");
        con.setValue1(new Long(ChiNhanhId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(nganhId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("nganhId.id");
        con.setValue1(new Long(nganhId));
        con.setOperator("eq");
        cons.add(con);	
    } 
    if(khoaId != 0 ){ 
        ConditionReport con = new ConditionReport(); 
        con.setCol("khoaId.id");
        con.setValue1(new Long(khoaId));
        con.setOperator("eq");
        cons.add(con);	
    } 
        preSearch(msg, cons); 
       if (msg.isPreMessage_b()) 
       { 
           if(pageSize == 0){ 
               pageSize = 20; 
           } 
            if(page == 0){ 
               page =1; 
           } 
           tblQLDTTXAHoSoXetTuyens = tblQLDTTXAHoSoXetTuyenService.findtblQLDTTXAHoSoXetTuyenByCondition(cons,pageSize,page); 
           pages = tblQLDTTXAHoSoXetTuyenService.counttblQLDTTXAHoSoXetTuyenByCondition(cons)/pageSize + 1; 
           postSearch(msg, cons); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
      dataString = ""; 
      /*dataString += "&diaChi=" + diaChi; 
      dataString += "&dienThoai=" + dienThoai;*/ 
      dataString += "&hoTen=" + hoTen; 
      dataString += "&ten=" + ten; 
      /*dataString += "&tungaySinh=" + tungaySinh; 
      dataString += "&denngaySinh=" + denngaySinh;*/ 
      dataString += "&noiSinh=" + noiSinh; 
      dataString += "&maHoSo=" + maHoSo;
      dataString += "&ThongBaoId=" + ThongBaoId;
      dataString += "&ChiNhanhId=" + ChiNhanhId;
      dataString += "&khoaId=" + khoaId;
      dataString += "&nganhId=" + nganhId;
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Seach tbl_QLDTTXA_HoSoXetTuyen Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 }

/*public String getTungaySinh() {
	return tungaySinh;
}

public void setTungaySinh(String tungaySinh) {
	this.tungaySinh = tungaySinh;
}

public String getDenngaySinh() {
	return denngaySinh;
}

public void setDenngaySinh(String denngaySinh) {
	this.denngaySinh = denngaySinh;
} */
 } 
 
